package adapter;/*
 *@创建者 lnn
 *@创建时间2016/8/3012:15
 *@描述 ${TODO}
*/

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.boltshow.R;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

import model.BoltDetails;

public class DetaisRecycleAdapter extends RecyclerView.Adapter<DetaisRecycleAdapter.MyViewHolder> {
    private List<BoltDetails.DataBean> mData;
    private Context mContext;
    private ImageOptions mImageOptions;
    private View.OnClickListener mListener;

    public DetaisRecycleAdapter(List<BoltDetails.DataBean> data, Context context) {
        mData = data;
        mContext = context;
        mImageOptions = new ImageOptions.Builder().setUseMemCache(true).build();

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_bolt_details, null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        BoltDetails.DataBean dataBean = mData.get(position);
        x.image().bind(holder.ivTitleLeft, dataBean.getImg640url(), mImageOptions);
        holder.tvPriceLeft.setText("¥" + dataBean.getCrazyPrice());
        holder.tvPricesLeft.setText("¥" + dataBean.getShopPrice());
        holder.tvZheLeft.setText(dataBean.getDiscount() + "闪折");
        holder.tvRedLeft.setText(dataBean.getFlashPrice());
        holder.tvInfoLeft.setText(dataBean.getGoodsName());
        holder.tlContainer.setTag(position);
        if (mListener != null) {

            holder.tlContainer.setOnClickListener(mListener);
        }
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView tvPriceLeft, tvPricesLeft, tvRedLeft, tvInfoLeft, tvZheLeft;
        private ImageView ivTitleLeft;
        private RelativeLayout tlContainer;

        public MyViewHolder(View itemView) {
            super(itemView);
            tvPriceLeft = (TextView) itemView.findViewById(R.id.tv_item_bolt_details_price_left);
            tvPricesLeft = (TextView) itemView.findViewById(R.id.tv_item_bolt_details_prices_left);
            tvRedLeft = (TextView) itemView.findViewById(R.id.tv_item_bolt_details_red_left);
            tvInfoLeft = (TextView) itemView.findViewById(R.id.tv_item_bolt_details_info_letf);
            tvZheLeft = (TextView) itemView.findViewById(R.id.tv_item_bolt_details_zhe_left);
            ivTitleLeft = (ImageView) itemView.findViewById(R.id.iv_item_bolt_details_left);
            tlContainer = (RelativeLayout) itemView.findViewById(R.id.ll_item_bolt_details_container);

        }
    }

    public void setOnClickListener(View.OnClickListener listener) {
        mListener = listener;
    }

}
